<%@ page pageEncoding="UTF-8"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="isperp" uri="/WEB-INF/tlds/isperp.tld"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<style>
.ul_div {
	float: left;
	width: 120px;
}

.ul_div ul {
	
}

.hspan {
	display: inline-block;;
}

.ul_div ul li {
	border: 1px solid #E9EDF1;
	text-align: center;
	padding: 2px;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

#changeCiCon ul {
	
}

.cili1 {
	border-bottom: 1px dashed #ddd;
}

.ulcihead {
	height: 35px;
	font-size: 14px;
	line-height: 30px;
	margin-left: 30px;
}
</style>
<tr>
	<td class="td2" colspan="3">
		<div class="header">
			<h3>变更清单</h3>
			<button onclick="return RelateChangeCi()" value="选择变更资产"
				class="button  button  nui-mainbtn" style="width:120px;">添加变更资产项</button>
			<div id="returnExcuteFunDivId" onclick="afterEditCi()"
				style="display:none"></div>
		</div>
	</td>

</tr>
<tr>
	<td class="td2" colspan="4">
		<div id="changeCiCon"></div></td>
</tr>

<script type="text/javascript">
	function afterEditCi() {
		var changeId = '${model.id }';
		rebulidCipropertyList(changeId);
	}

	function rebulidCipropertyList(changeId) {

		//加载资产变更属性列表
		$
				.getJSON(
						"configuration/ciUseRelation/listCiChangeProperty?changeId="
								+ changeId,
						function(resultData) {
							//加载资产变更属性列表
							var tciid = "";
							var ci_length = 0;
							var ciidarr = new Array();
							for ( var j = 0; j < resultData.length; j++) {
								var ciid = resultData[j].ci_id;
								if (tciid != ciid) {
									ci_length += 1;
									ciidarr.push(ciid);
								}
								tciid = ciid;
							}
							for ( var i = 0; i < ci_length; i++) {
								var trStr = "<tr id='tr_ci_"+ciidarr[i]+"'><td><div style='width:100%;overflow:auto;margin-left:40px;'>";
								trStr += "<div class='ul_div'><ul><li>&nbsp;</li>"
										+ "<li>当前值：</li>"
										+ "<li style='font-weight:bold'>计划变更值：</li></ul></div>";
								for ( var k = 0; k < resultData.length; k++) {
									var ciid = resultData[k].ci_id;
									var columnname = resultData[k].columnname;
									var columnvalue = resultData[k].columnvalue;
									var columnvalue_before = resultData[k].columnvalue_before;
									if (columnvalue_before == "")
										columnvalue_before = "&nbsp;";
									if (columnvalue == "")
										columnvalue = "&nbsp;";

									if (ciid == ciidarr[i]) {

										trStr += "<div class='ul_div'><ul><li style='font-weight:bold'>"
												+ columnname
												+ "</li>"
												+ "<li title='"+columnvalue_before+"'>"
												+ columnvalue_before
												+ "</li>"
												+ "<li title='"+columnvalue+"'>"
												+ columnvalue
												+ "</li></ul></div>";
									}

								}
								trStr += "</div></td></tr>";

								$("#tr_ci_" + ciidarr[i]).remove();
								$("#table_ci_" + ciidarr[i]).append($(trStr));

							}

						});

	}

	function editChangeCi(ciId) {
		var chgId = '${model.id }';

		isperp.openDialog({
			title : "编辑资产",
			contentUrl : "configuration/ci/changeEdit?changeId=" + chgId
					+ "&id=" + ciId
		});

	}

	function viewChangeCi(ciId) {
		isperp.openDialog({
			title : "查看资产履历",
			contentUrl : "configuration/ci/ciResumeView?id=" + ciId
					+ "&keyword="
		});

	}

	function deleteChangeCi(ciId) {
		var chgId = '${model.id }';
		$
				.ajax({
					type : "get",
					url : "configuration/ciUseRelation/deleteCiRelationAndChangeRelateProperty",
					data : {
						changeId : chgId,
						ciId : ciId
					},
					success : function(data) {
						$("#table_ci_" + ciId).parent().remove();
					},
					error : function(data) {
						alert("删除失败！");
					}
				});

	}

	function RelateChangeCi() {
		selectCi();
		return false;
	}

	//选择资产后执行构造变更资产列表 
	function createChangeCiList() {
		var changeId = '${model.id }';
		$
				.getJSON(
						"configuration/ciUseRelation/listDetail?relationId="
								+ changeId,
						function(data) {
							//alert(data.content[0].ci_id);
							var appendStr = "<ul>";
							for ( var i = 0; i < data.content.length; i++) {
								var cicode = data.content[i].code;
								var cicty = data.content[i].conf_category_name;
								var ciid = data.content[i].ci_id;
								var ciname = data.content[i].name;

								appendStr += "<li class='cili1'><table id='table_ci_"+ciid+"'><tr><td style='border:none;'><div class='ulcihead'><div class='hspan'><b>资产编号：</b>"
										+ cicode
										+ "</div><div class='hspan'>&nbsp;&nbsp;&nbsp;类型："
										+ cicty
										+ "</div><div class='hspan'>&nbsp;&nbsp;&nbsp;名称："
										+ ciname
										+ "</div>&nbsp;&nbsp;&nbsp;<span class='ui-icon icon-view' title='查看' onclick=\"viewChangeCi('"
										+ ciid
										+ "')\"></span>&nbsp;&nbsp;<span class='ui-icon ui-icon-pencil' title='进入编辑需要变更的资产属性' onclick=\"editChangeCi('"
										+ ciid
										+ "')\"></span>&nbsp;&nbsp;<span class='ui-icon ui-icon-trash' title='删除' onclick=\"deleteChangeCi('"
										+ ciid
										+ "')\"></span></div></td></tr></table></li>"
							}
							appendStr += "</ul>";
							$("#changeCiCon").html("");
							$("#changeCiCon").append($(appendStr));

							//加载资产变更属性列表
							rebulidCipropertyList(changeId);
						});
	}
</script>


